# Maintainer: Vincent Torri <vincent.torri@gmail.com>

_realname=libdwarf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.0.0
pkgrel=1
pkgdesc="A library for handling DWARF Debugging Information Format (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.prevanders.net/dwarf.html'
msys2_repository_url="https://github.com/davea42/libdwarf-code"
license=('spdx:LGPL-2.1-only AND BSD-3-Clause AND GPL-2.0-only AND BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=("https://github.com/davea42/libdwarf-code/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz")
sha256sums=('c3d1db72a979e14ee60b93010f0698d30fc1bca4eb1341006783d4e9c9ec7e72')

build() {
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=release \
      -Ddefault_library=shared \
      -Ddwarfgen=true \
      -Ddwarfexample=true \
      -Ddoc=true \
      "build-${MSYSTEM}" \
      "${_realname}-${pkgver}"

  meson compile -C "build-${MSYSTEM}"
}

check() {
  meson test -C "build-${MSYSTEM}"
}

package() {
  meson install -C "build-${MSYSTEM}" --destdir "${pkgdir}"

  cd "${_realname}-${pkgver}"

  install -Dm644 COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 src/bin/dwarfgen/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/BSD-3-Clause.txt
  install -Dm644 src/lib/libdwarf/LGPL.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LGPL.txt
  install -Dm644 src/lib/libdwarf/LIBDWARFCOPYRIGHT "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LIBDWARFCOPYRIGHT"
  install -Dm644 src/bin/dwarfdump/GPL.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/GPL.txt
  install -Dm644 src/bin/dwarfdump/DWARFDUMPCOPYRIGHT "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/DWARFDUMPCOPYRIGHT
}
